package edu.pku.sei.modeler.ui.editors;

import java.util.List;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IMenuManager;

import edu.pku.sei.modeler.actions.registry.EditorActionGroup;
import edu.pku.sei.modeler.actions.registry.MetaModelActionRegistry;
import edu.pku.sei.modeler.model.structure.MetaDiagram;

public class GraphicalEditorContextMenuProvider extends ContextMenuProvider {
	private ActionRegistry actionRegistry;
	private Object diagram;
    public GraphicalEditorContextMenuProvider(EditPartViewer viewer, Object diagram, ActionRegistry registry) {
        super(viewer);
        this.diagram = diagram;
        actionRegistry = registry;
    }
    public void buildContextMenu(IMenuManager menu) {
    	GEFActionConstants.addStandardActionGroups(menu);
    	List list = this.getViewer().getSelectedEditParts();
    	List<EditorActionGroup> actionGroups;
    	//get registed action groups
    
    	actionGroups = MetaModelActionRegistry.getDefault().getEditorActionGroups(getViewer(), this.actionRegistry, (MetaDiagram) diagram);
    	
    	
    	for (EditorActionGroup actionGroup : actionGroups) {
			actionGroup.fillContextMenu(menu);
		}
    }   
}
